/**
 *
 * @author Cristhy
 */

package almacenamiento_lab6;
import java.util.ArrayList;
import java.util.List;
import java.util.*;

public class TareaLeerNTuplas {
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);

        List<Atributo> attrs = new ArrayList<Atributo>();
            attrs.add(new Atributo("character", Character.class));
            attrs.add(new Atributo("byte", Byte.class));
            attrs.add(new Atributo("short", Short.class));
            attrs.add(new Atributo("integer", Integer.class));
            attrs.add(new Atributo("long", Long.class));
            attrs.add(new Atributo("float", Float.class));
            attrs.add(new Atributo("double", Double.class));
            attrs.add(new Atributo("string", String.class));
            Relacion rel = new Relacion(attrs);

 
            System.out.print("Ingrese el numero de tuplas : ");
            int nroTuplas = in.nextInt();

            //List<Comparable> lista = new ArrayList<Comparable>();

            List<GestorIOTupla> listas = new ArrayList<GestorIOTupla>();
            List<Tupla> listaTupla = new ArrayList<Tupla>();

            for (int i = 0; i < nroTuplas; i++)
            {
                System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
                System.out.println("        Tupla N :"+(i+1));
                 System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
                System.out.println("Ingrese los datos siguientes: ");
              List<Comparable> valores = new ArrayList<Comparable>();
             System.out.println("Char:");
             Scanner n1=new Scanner(System.in);
             valores.add(new Character(n1.next().toCharArray()[0]));
            System.out.println("Byte:");
            valores.add(new Byte(n1.nextByte()));
            System.out.println("Short:");
            valores.add(n1.nextShort());
            System.out.println("Integer:");
            valores.add(new Integer(n1.nextInt()));
            System.out.println("Long:");
            valores.add(n1.nextLong());
            System.out.println("Float:");
            valores.add(Float.parseFloat(n1.next()));
            System.out.println("Double:");
            valores.add(Double.parseDouble(n1.next()));
            System.out.println("String:");
            valores.add(n1.next());

                Tupla t = new Tupla(new IdentificadorTupla("redes"+i, i), valores);
                GestorIOTupla man = new GestorIOTupla(rel, "redes"+i);

                listaTupla.add(t);
                listas.add(man);

            }
            int inicio =0;
            for (int j = 0; j < nroTuplas; j++) {
                Tupla t = listaTupla.get(j);
                System.out.println("writing tuple..." + t);
                byte[] bytes = new byte[1024];
                GestorIOTupla a  = listas.get(j);
                a.escribirTupla(t, bytes, inicio);

                System.out.println("Mostrando el arreglo de bytes: "+bytes);

                System.out.println("reading tuple...");
                // t = man.leerTupla(bytes);
                Par<Tupla, Integer> st = a.leerTupla(bytes, inicio);
                System.out.println(st);
                inicio+=st.segundo;
                System.out.println("-------------------------------------------");
                System.out.println();

            }
        }
}
